package com.systemdemo;

public class SystemDemo3 {
    public static void main(String[] args) {
        //public static void arraycopy(数据源数组，起始索引，目的地数组，起始索引，拷贝个数)    数组拷贝
        //细节:
        //1.如果数据源数组和目的地数组都是基本数据类型，那么两者的类型必须保持一致，否则会报错
        //2.在拷贝的时候需要考虑数组的长度，如果超出范围也会报错
        //3.如果数据源数组和目的地数组都是引用数据类型，那么两者的类型必须保持一致，否则会报错
//        int[] arr1={1,2,3,4,5,6,7,8,9,10};
//        double[] arr2=new double[10];
//
//        System.arraycopy(arr1,0,arr2,0,10);
//        for (int i = 0; i < arr2.length; i++) {
//            System.out.print(arr2[i]+" ");
//        }

        Student student1 = new Student("zhangshan", 23);
        Student student2 = new Student("lishi", 24);
        Student student3 = new Student("wangwu", 25);
        Student[] arr1={student1,student2,student3};
        Person[] arr2 = new Person[3];
        //把arr1中对象的地址值赋值给arr2中
        System.arraycopy(arr1,0,arr2,0,3);
        //遍历数组arr2
        for (int i = 0; i < arr2.length; i++) {
            Student student = (Student) arr2[i];
            System.out.println(student.getName()+","+student.getAge());
        }
    }

}
class Person{
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

class Student extends Person{
    public Student() {
    }

    public Student(String name, int age) {
        super(name, age);
    }
}